package zjut.cocouml.command;

import org.eclipse.gef.commands.Command;

import zjut.cocouml.model.BCanvas;
import zjut.cocouml.model.BInterface;

public class BInterfaceModifyCommand extends Command{

	private BInterface model;
	
	private String oldModifiers;
	private String newModifiers;
	
	private String oldInterfaceName;
	private String newInterfaceName;
	
	public boolean canExecute() {
		return !((BCanvas)model.getParent()).getFiletable().containsKey(newInterfaceName);
	}
	
	public void execute() {
		this.oldInterfaceName = model.getInterfaceName();
		this.oldModifiers = model.getModifiers();
		
		model.setModifiers(newModifiers);
		model.setInterfaceName(newInterfaceName);
		
		this.model.setDisplayName(this.model.getDisplayName());
		((BCanvas)model.getParent()).getFiletable().put(newInterfaceName,this.model);
		((BCanvas)model.getParent()).getFiletable().remove(oldInterfaceName);
	}
	
	public void undo() {
		model.setInterfaceName(oldInterfaceName);
		model.setModifiers(oldModifiers);
		
		this.model.setDisplayName(model.getDisplayName());
		((BCanvas)model.getParent()).getFiletable().remove(newInterfaceName);
		((BCanvas)model.getParent()).getFiletable().put(oldInterfaceName,this.model);
	}
	
	public void setModel(BInterface model) {
		this.model = model;
	}

	public void setOldModifiers(String oldModifiers) {
		this.oldModifiers = oldModifiers;
	}

	public void setNewModifiers(String newModifiers) {
		this.newModifiers = newModifiers;
	}

	public void setOldInterfaceName(String oldInterfaceName) {
		this.oldInterfaceName = oldInterfaceName;
	}

	public void setNewInterfaceName(String newInterfaceName) {
		this.newInterfaceName = newInterfaceName;
	}
	
}
